---------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexEmpirical/Conditional/Mandates/PredictedValues.log
  log type:  text
 opened on:  12 Nov 2016, 20:44:09

. cd "/Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexEmpirical/Conditional/Mandates";
/Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexEmpirical/Conditional/Mandates

. **************************************************************;
. *Author: Jeff Carter                                         *;
. *Date: Tuesday, May 26, 2015                              *;
. *Purpose: Simulating Predictions                *;
. **************************************************************;
. *********************************;
. **      Peace to War            *;
. *********************************;
. use "/Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexEmpirical/Conditional/Mandates/SimData.dta";

. postutil clear;

. postfile mypost prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 prob_hat2 lo2 hi2 
>                 diff_hat0 diff_lo0 diff_hi0 diff_hat1 diff_lo1 diff_hi1
>                 prob_hat01 lo01 hi01 prob_hat11 lo11 hi11 prob_hat21 lo21 hi21
>                 diff_hat01 diff_lo01 diff_hi01 diff_hat11 diff_lo11 diff_hi11
>                 delta_hat delta_lo delta_hi delta_hat1 delta_lo1 delta_hi1 using PredictedValues, replace;
(note: file PredictedValues.dta not found)

. noisily display "start";
start

. local a=-1 ;

. while `a' < 4 { ;
  2. {;
  3. *tl2 milservice tl2_mil tl1 tl1_mil;
.  scalar h_Accountable =   0  ;
  4. scalar h_LameDuck= 1  ;
  5. scalar h_Civilian = 0;
  6. scalar h_Military = 1;
  7. scalar h_Constant = 1;
  8. scalar h_OneTerm=1;
  9. scalar h_TwoTerms=1;
 10. scalar h_Parliament = 0;
 11. scalar h_CivilWar = 0;
 12. scalar h_GDPpc =  12589.35;
 13. scalar h_Growth = 3.453132;
 14. scalar h_MajorPower = 0;
 15. scalar h_Borders = 2;
 16. scalar h_Mobilization =  -.0008714 ;
 17. scalar h_Time = 5;
 18.  scalar h_Rivalry = 0;
 19. scalar h_Female = 0;
 20. generate x_betahat0 = MG_b1*h_Accountable
>     + MG_b2*`a'
>     + MG_b3*(h_Accountable*`a')
>     + MG_b4*h_Accountable
>     + MG_b5*(h_Accountable*`a')
>     + MG_b6*h_Rivalry
>     + MG_b7*h_Borders
>     + MG_b8*h_Parliament
>     + MG_b9*h_Female
>     + MG_b10*h_Time
>     + MG_b11*(h_Time^2)
>     + MG_b12*(h_Time^3)
>     + MG_b13*h_Constant;
 21.  generate x_betahat1 = MG_b1*h_OneTerm
>     + MG_b2*`a'
>     + MG_b3*(h_OneTerm*`a')
>     + MG_b4*h_Accountable
>     + MG_b5*(h_Accountable*`a')
>     + MG_b6*h_Rivalry
>     + MG_b7*h_Borders
>     + MG_b8*h_Parliament
>     + MG_b9*h_Female
>     + MG_b10*h_Time
>     + MG_b11*(h_Time^2)
>     + MG_b12*(h_Time^3)
>     + MG_b13*h_Constant;
 22.  generate x_betahat2 = MG_b1*h_Accountable
>     + MG_b2*`a'
>     + MG_b3*(h_Accountable*`a')
>     + MG_b4*h_TwoTerms
>     + MG_b5*(h_TwoTerms*`a')
>     + MG_b6*h_Rivalry
>     + MG_b7*h_Borders
>     + MG_b8*h_Parliament
>     + MG_b9*h_Female
>     + MG_b10*h_Time
>     + MG_b11*(h_Time^2)
>     + MG_b12*(h_Time^3)
>     + MG_b13*h_Constant;
 23.   gen prob0=1/(1+exp(-x_betahat0));
 24. gen prob1=1/(1+exp(-x_betahat1));
 25. gen prob2=1/(1+exp(-x_betahat2));
 26.  gen diff0=prob1-prob0 ;
 27. gen diff1=prob2-prob0 ;
 28. egen probhat0=mean(prob0) ;
 29. egen probhat1=mean(prob1) ;
 30. egen probhat2=mean(prob2) ;
 31. egen diffhat0=mean(diff0) ;
 32. egen diffhat1=mean(diff1) ;
 33. generate x_betahat01 =   MG_b1*h_Accountable
>     + MG_b2*`a'
>     + MG_b3*(h_Accountable*`a')
>     + MG_b4*h_Accountable
>     + MG_b5*(h_Accountable*`a')
>     + MG_b6*h_Rivalry
>     + MG_b7*h_Borders
>     + MG_b8*h_Parliament
>     + MG_b9*h_Female
>     + MG_b10*h_Time
>     + MG_b11*(h_Time^2)
>     + MG_b12*(h_Time^3)
>     + MG_b13*h_Constant;
 34.  generate x_betahat11 =   MG_b1*h_OneTerm
>     + MG_b2*`a'
>     + MG_b3*(h_OneTerm*`a')
>     + MG_b4*h_Accountable
>     + MG_b5*(h_Accountable*`a')
>     + MG_b6*h_Rivalry
>     + MG_b7*h_Borders
>     + MG_b8*h_Parliament
>     + MG_b9*h_Female
>     + MG_b10*h_Time
>     + MG_b11*(h_Time^2)
>     + MG_b12*(h_Time^3)
>     + MG_b13*h_Constant;
 35.   generate x_betahat21 =   MG_b1*h_Accountable
>     + MG_b2*`a'
>     + MG_b3*(h_Accountable*`a')
>     + MG_b4*h_TwoTerms
>     + MG_b5*(h_TwoTerms*`a')
>     + MG_b6*h_Rivalry
>     + MG_b7*h_Borders
>     + MG_b8*h_Parliament
>     + MG_b9*h_Female
>     + MG_b10*h_Time
>     + MG_b11*(h_Time^2)
>     + MG_b12*(h_Time^3)
>     + MG_b13*h_Constant;
 36.   gen prob01=1/(1+exp(-x_betahat01));
 37. gen prob11=1/(1+exp(-x_betahat11));
 38. gen prob21=1/(1+exp(-x_betahat21));
 39. gen diff01=prob11-prob01 ;
 40. gen diff11=prob21-prob01 ;
 41. egen probhat01=mean(prob01) ;
 42. egen probhat11=mean(prob11) ;
 43. egen probhat21=mean(prob21) ;
 44. egen diffhat01=mean(diff01) ;
 45. egen diffhat11=mean(diff11) ;
 46. gen delta=diff01-diff0;
 47. gen delta1=diff11-diff1;
 48. egen deltahat=mean(delta);
 49. egen deltahat1=mean(delta1);
 50. tempname prob_hat0 lo0 hi0 prob_hat1 lo1 hi1 prob_hat2 lo2 hi2
>          diff_hat0 diff_lo0 diff_hi0 diff_hat1 diff_lo1 diff_hi1
>          prob_hat01 lo01 hi01 prob_hat11 lo11 hi11 prob_hat21 lo21 hi21
>          diff_hat01 diff_lo01 diff_hi01 diff_hat11 diff_lo11 diff_hi11
>          delta_hat delta_lo delta_hi  delta_hat1 delta_lo1 delta_hi1;
 51.     _pctile prob0, p(2.5,97.5) ;
 52.     scalar `lo0'=r(r1) ;
 53.     scalar `hi0'=r(r2) ;
 54.     _pctile prob1, p(2.5,97.5) ;
 55.     scalar `lo1'=r(r1) ;
 56.     scalar `hi1'=r(r2) ;
 57.     _pctile prob2, p(2.5,97.5) ;
 58.     scalar `lo2'=r(r1) ;
 59.     scalar `hi2'=r(r2) ;
 60.         _pctile diff0, p(2.5,97.5) ;
 61.     scalar `diff_lo0'= r(r1) ;
 62.     scalar `diff_hi0'=r(r2) ;
 63.     _pctile diff1, p(2.5,97.5) ;
 64.     scalar `diff_lo1'= r(r1) ;
 65.     scalar `diff_hi1'=r(r2) ;
 66.     scalar `prob_hat0'=probhat0 ;
 67.     scalar `prob_hat1'=probhat1 ;
 68.     scalar `prob_hat2'=probhat2 ;
 69.     scalar `diff_hat0'=diffhat0 ;
 70.     scalar `diff_hat1'=diffhat1 ;
 71.        _pctile prob01, p(2.5,97.5) ;
 72.     scalar `lo01'=r(r1) ;
 73.     scalar `hi01'=r(r2) ;
 74.     _pctile prob11, p(2.5,97.5) ;
 75.     scalar `lo11'=r(r1) ;
 76.     scalar `hi11'=r(r2) ;
 77.     _pctile prob21, p(2.5,97.5) ;
 78.     scalar `lo21'=r(r1) ;
 79.     scalar `hi21'=r(r2) ;
 80.     _pctile diff01, p(2.5,97.5) ;
 81.     scalar `diff_lo01'= r(r1) ;
 82.     scalar `diff_hi01'=r(r2) ;
 83.     _pctile diff11, p(2.5,97.5) ;
 84.     scalar `diff_lo11'= r(r1) ;
 85.     scalar `diff_hi11'=r(r2) ;
 86.     scalar `prob_hat01'=probhat01 ;
 87.     scalar `prob_hat11'=probhat11 ;
 88.     scalar `prob_hat21'=probhat21 ;
 89.     scalar `diff_hat01'=diffhat01 ;
 90.     scalar `diff_hat11'=diffhat11 ;
 91.     _pctile delta, p(2.5,97.5) ;
 92.     scalar `delta_lo'= r(r1) ;
 93.     scalar `delta_hi'=r(r2) ;
 94.     _pctile delta1, p(2.5,97.5) ;
 95.     scalar `delta_lo1'= r(r1) ;
 96.     scalar `delta_hi1'=r(r2) ;
 97.     scalar `delta_hat'=deltahat;
 98.     scalar `delta_hat1'=deltahat1;
 99.     post mypost (`prob_hat0') (`lo0') (`hi0') (`prob_hat1') (`lo1') (`hi1') (`prob_hat2') (`lo2') (`hi2')
>                 (`diff_hat0') (`diff_lo0') (`diff_hi0') (`diff_hat1') (`diff_lo1') (`diff_hi1')
>                 (`prob_hat01') (`lo01') (`hi01') (`prob_hat11') (`lo11') (`hi11')  (`prob_hat21') (`lo21') (`hi21')
>                 (`diff_hat01') (`diff_lo01') (`diff_hi01') (`diff_hat11') (`diff_lo11') (`diff_hi11')
>                 (`delta_hat') (`delta_lo') (`delta_hi') (`delta_hat1') (`delta_lo1') (`delta_hi1')
> 
>     ;
100.     } ;
101.     drop    x_betahat0 x_betahat1 x_betahat2
>             prob0 prob1 prob2 
>             diff0 diff1
>             probhat0 probhat1 probhat2
>             diffhat0 diffhat1
>             x_betahat01 x_betahat11 x_betahat21
>             prob01 prob11 prob21
>             diff01 diff11
>             probhat01 probhat11 probhat21
>             diffhat01 diffhat11
>             delta deltahat delta1 deltahat1;
102.     local a=`a'+ 1 ;
103.     display "." _c ;
104.     } ;
.....
. display "" ;


.  postclose mypost ;

. use PredictedValues, clear;

. gen ruler = _n;

. sum;

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
   prob_hat0 |         5    .0654093    .0249807   .0379864   .1008413
         lo0 |         5     .041898    .0152766    .021888   .0598203
         hi0 |         5    .0972133    .0395681   .0606428   .1583769
   prob_hat1 |         5    .0400719    .0270075   .0156946   .0824503
         lo1 |         5    .0127485    .0049069   .0049122   .0173146
-------------+--------------------------------------------------------
         hi1 |         5    .0982204    .0909147   .0356165   .2503609
   prob_hat2 |         5    .0654482    .0128952   .0556561   .0872159
         lo2 |         5    .0150054    .0087552   .0035145   .0253879
         hi2 |         5    .1934321    .0740577   .1181129   .2884223
   diff_hat0 |         5   -.0253374    .0048981  -.0301485   -.018391
-------------+--------------------------------------------------------
    diff_lo0 |         5   -.0670234    .0279108  -.1123351  -.0465888
    diff_hi0 |         5    .0347414    .0680742  -.0091837   .1520691
   diff_hat1 |         5    .0000389    .0167293  -.0137013   .0255597
    diff_lo1 |         5   -.0596493    .0276114  -.1068944  -.0418778
    diff_hi1 |         5     .127493    .0830465   .0502432   .2527612
-------------+--------------------------------------------------------
  prob_hat01 |         5    .0654093    .0249807   .0379864   .1008413
        lo01 |         5     .041898    .0152766    .021888   .0598203
        hi01 |         5    .0972133    .0395681   .0606428   .1583769
  prob_hat11 |         5    .0400719    .0270075   .0156946   .0824503
        lo11 |         5    .0127485    .0049069   .0049122   .0173146
-------------+--------------------------------------------------------
        hi11 |         5    .0982204    .0909147   .0356165   .2503609
  prob_hat21 |         5    .0654482    .0128952   .0556561   .0872159
        lo21 |         5    .0150054    .0087552   .0035145   .0253879
        hi21 |         5    .1934321    .0740577   .1181129   .2884223
  diff_hat01 |         5   -.0253374    .0048981  -.0301485   -.018391
-------------+--------------------------------------------------------
   diff_lo01 |         5   -.0670234    .0279108  -.1123351  -.0465888
   diff_hi01 |         5    .0347414    .0680742  -.0091837   .1520691
  diff_hat11 |         5    .0000389    .0167293  -.0137013   .0255597
   diff_lo11 |         5   -.0596493    .0276114  -.1068944  -.0418778
   diff_hi11 |         5     .127493    .0830465   .0502432   .2527612
-------------+--------------------------------------------------------
   delta_hat |         5           0           0          0          0
    delta_lo |         5           0           0          0          0
    delta_hi |         5           0           0          0          0
  delta_hat1 |         5           0           0          0          0
   delta_lo1 |         5           0           0          0          0
-------------+--------------------------------------------------------
   delta_hi1 |         5           0           0          0          0
       ruler |         5           3    1.581139          1          5

. saveold PredictedValues, replace;
file PredictedValues.dta saved

. log close;
      name:  <unnamed>
       log:  /Users/Jeff/Dropbox/TermLimits/Replication/Models/IndexEmpirical/Conditional/Mandates/PredictedValues.log
  log type:  text
 closed on:  12 Nov 2016, 20:44:10
---------------------------------------------------------------------------------------------------------------------------
